package demo5;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 * Date: 2023-08-16
 * Time: 16:40
 */
class Student{
    public String name;
    public double score;
    public int age;
    public Student(String name,double score,int age){
        this.name=name;
        this.score=score;
        this.age=age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score='" + score + '\'' +
                '}';
    }
}
class AgeComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}
class ScoreComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return (int)(o1.score-o2.score);
    }
}
public class Test {

    public static void main(String[] args) {
        Student[] array=new Student[3];
        array[0]=new Student("zhangsan",80,89);
        array[1]=new Student("qwer",7,123);
        AgeComparator ageComparator=new AgeComparator();
        System.out.println(ageComparator.compare(array[0], array[1]));
        System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        ScoreComparator scoreComparator=new ScoreComparator();
        System.out.println(scoreComparator.compare(array[0], array[1]));
    }
}

































